package com.example.android.ui.activity

import com.blankj.utilcode.util.ToastUtils
import com.example.android.databinding.ActivityAppbarBinding
import com.google.android.material.appbar.AppBarLayout
import com.zxf.basic.base.BindingActivity
import com.zxf.basic.expand.newIntent
import com.zxf.basic.expand.signClick
import kotlin.math.abs

/**
 * @author zjc
 * @date 2024/4/16
 *
 * 测试appbar
 */
class AppbarActivity : BindingActivity<ActivityAppbarBinding>(ActivityAppbarBinding::inflate) {
    private var name: String = ""

    override fun initView() {
        binding.apply {
            appbarLayout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { appBarLayout, offset ->
                val scrollRange = appBarLayout.totalScrollRange.toFloat()
                ivToolbar.alpha = abs(offset) / scrollRange
            })
            ivBack.signClick {
                val intent = newIntent<MainActivity> {
                    putExtra("name", name)
                }
                setResult(100, intent)
                finish()
            }
        }
    }

    override fun initData() {
        name = intent.getStringExtra("name") ?: ""
        ToastUtils.showShort(name)
    }

}